package com.ruoyi.web.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RemoveHtmlCode {
    public static void main(String[] args) {
        String text = "<p>这是一段含有HTML代码的文本。</p><br><b>这是加粗的文本。</b>";
        String result = removeHtmlCode(text);
        System.out.println(result);
    }

    public static String removeHtmlCode(String text) {
        String regex = "<.*?>";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(text);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, "");
        }
        matcher.appendTail(sb);
        return sb.toString();
    }
}